package com.campol.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.campol.R;
import com.campol.activity.PostsListingActivity;
import com.campol.model.Reporter;

public class ReportersAdapter extends ArrayAdapter<Reporter> {

	private LayoutInflater inflater;

	public ReportersAdapter(Context context, List<Reporter> items) {
		super(context, 0, 0, items);
		inflater = LayoutInflater.from(context);
	}

	@Override
	public int getItemViewType(int position) {
		return PostsListingActivity.ITEM_TYPE_REPORTER;
	}

	@Override
	public boolean areAllItemsEnabled() {
		return false;
	}

	@Override
	public boolean isEnabled(int position) {
		return false;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LinearLayout rl = (LinearLayout) convertView;

		ViewHolder viewHolder;
		if (rl == null) {
			viewHolder = new ViewHolder();
			rl = (LinearLayout) inflater.inflate(R.layout.report_item, null,
					false);
			viewHolder.title = (TextView) rl
					.findViewById(R.id.reporter_item_title);

			rl.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) rl.getTag();
		}

		Reporter item = getItem(position);

		viewHolder.title.setText(item.FirstName + " " + item.LastName);

		return rl;
	}

	private class ViewHolder {
		public TextView title;
	}
}
